<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
function paginate($page, $limit)
{
    $page = $page ? $page : 1;
    $limit = $limit ? $limit : 10;
    $skip = ($page > 0 ? $page - 1 : 0) * $limit;
    return [$limit, $skip];
}


function user_ins()
{
    return new App\User;
}

function question_ins()
{
    return new App\Question;
}

function answer_ins()
{
    return new App\Answer;
}

function comment_ins()
{
    return new App\Comment;
}

function rq($key = null, $val = null)
{
    if (empty($key))
        return Request::all();
    return Request::get($key, $val);
}

function err($msg = null)
{
    return ['status' => 0, 'msg' => $msg];
}

function suc($data_to_merge = [])
{
    $data = ['status' => 200];
    if ($data_to_merge)
        $data = array_merge($data, $data_to_merge);
    return $data;
}

//login
function is_logged_in()
{
    return session('username') ?: false;
}


Route::get('/', function () {
    return view('index');
});

Route::any('api', function () {
    return ['version' => 0.1];
});

Route::any('api/signup', function () {

    return user_ins()->signUp();
});
//用户信息
Route::any('api/user/read', function () {

    return user_ins()->read();
});


Route::any('api/login', function () {

    return user_ins()->login();
});

Route::any('api/logout', function () {

    return user_ins()->logOut();
});
//用户名查重
Route::any('api/user/exist', function () {

    return user_ins()->exist();
});
//修改密码
Route::any('api/user/change_password', function () {

    return user_ins()->change_password();
});
//重置密码
Route::any('api/user/reset_password', function () {

    return user_ins()->reset_password();
});

Route::any('api/user/validate_reset_password', function () {

    return user_ins()->validate_reset_password();
});


Route::any('api/question/add', function () {

    return question_ins()->add();
});

Route::any('api/question/change', function () {

    return question_ins()->change();
});

Route::any('api/question/read', function () {

    return question_ins()->read();
});

Route::any('api/question/remove', function () {

    return question_ins()->remove();
});

Route::any('api/answer/add', function () {

    return answer_ins()->add();
});

Route::any('api/answer/change', function () {

    return answer_ins()->change();
});

Route::any('api/answer/read', function () {

    return answer_ins()->read();
});

Route::any('api/answer/vote', function () {

    return answer_ins()->vote();
});

Route::any('api/comment/add', function () {

    return comment_ins()->add();
});

Route::any('api/comment/read', function () {

    return comment_ins()->read();
});

Route::any('api/comment/remove', function () {

    return comment_ins()->remove();
});

Route::any('api/timeLine', 'CommonController@timeLine');
Route::any('api/test', 'CommonController@test');

Route::get('tpl/page/home', function () {

    return view('page.home');
});

Route::get('tpl/page/signup', function () {

    return view('page.signup');
});

Route::get('tpl/page/login', function () {

    return view('page.login');
});

Route::get('tpl/page/question_add', function () {

    return view('page.question_add');
});

//
Route::get('tpl/page/user', function () {

    return view('page.user');
});
//
Route::get('tpl/page/question_detail', function () {

    return view('page.question_detail');
});



















